"""
流式多代理工作流模块
提供流式处理能力的多代理研究助理工作流实现
"""

import logging
from typing import Dict, Any, AsyncGenerator

# 配置日志记录
logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger(__name__)

# 从增强版多代理工作流导入所需类
from .enhanced_multi_agent_workflow import (
    create_enhanced_multi_agent_workflow,
    EnhancedMultiAgentState
)

async def stream_multi_agent_response(question: str) -> AsyncGenerator[Dict[str, Any], None]:
    """
    流式处理多代理响应
    
    Args:
        question: 研究问题
        
    Yields:
        工作流执行过程中的各个步骤结果
    """
    try:
        # 创建增强版多代理工作流
        workflow = create_enhanced_multi_agent_workflow()
        
        # 定义初始状态
        initial_state = EnhancedMultiAgentState(
            question=question,
        )
        
        # 流式执行工作流
        async for chunk in workflow.astream(initial_state):
            yield chunk
            
    except Exception as e:
        logger.error(f"流式处理多代理响应时出错: {e}")
        yield {"error": str(e)}